<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>事件处理</title>
</head>
<body>
  <div id="app"></div>
  <script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
  <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
  <!-- 使用jsx需要babel转义 -->
  <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
  <!-- 使用babel需要申明type -->
  <script type="text/babel">
    const tag = document.getElementById('app')
    class Toggle extends React.Component{       
      constructor(props) {
        super(props)
        this.state = {
          isToggleOn: true
        }
        console.log('constructor----->',this)
      }
      // 调用的地方使用this或者使用箭头函数
      handleClick(title) {
        alert(title)
        console.log('handleClick----->',this)
        this.setState( prevState => ({
          isToggleOn: !prevState.isToggleOn
        }))
      }
      render() {
        console.log('render----->',this)
        return (<button onClick={() => this.handleClick()}>
          {this.state.isToggleOn ? 'ON' : 'OFF' }
         </button>)
        // return (<button onClick={this.handleClick.bind(this,'abc')}>
        //   {this.state.isToggleOn ? 'ON' : 'OFF' }
        //  </button>)
      }
    }
    ReactDOM.render(
      <Toggle/>,
      tag
    )
  </script>
</body>
</html>